package com.goodving.guli.bt.utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Build;
import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.RenderScript;
import android.renderscript.ScriptIntrinsicBlur;

import com.goodving.guli.bt.model.PersonInfo;
import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.bt.profile.scale.HeartRateInfo;

import java.lang.reflect.Array;

/**
 * Created by john on 2015/12/4.
 */
public class C0880d {
    private static final String f4461a = "Blur";

    @SuppressLint({"NewApi"})
    public static Bitmap m9051a(Context context, Bitmap bitmap, int i) {
        Bitmap bitmap2;
        if (Build.VERSION.SDK_INT > 16) {
            if (bitmap.isMutable()) {
                bitmap2 = bitmap;
            } else {
                bitmap2 = bitmap.copy(bitmap.getConfig(), true);
                if (bitmap2 == null) {
                    return null;
                }
                GuliLog.tracePrintInfo(f4461a, "Copy inBitmap for outBitmap!!");
            }
            RenderScript create = RenderScript.create(context);
            Allocation createFromBitmap = Allocation.createFromBitmap(create, bitmap, Allocation.MipmapControl.MIPMAP_NONE, 1);
            Allocation createTyped = Allocation.createTyped(create, createFromBitmap.getType());
            ScriptIntrinsicBlur create2 = ScriptIntrinsicBlur.create(create, Element.U8_4(create));
            create2.setRadius((float) i);
            create2.setInput(createFromBitmap);
            create2.forEach(createTyped);
            createTyped.copyTo(bitmap2);
            return bitmap2;
        }
        bitmap2 = bitmap.copy(bitmap.getConfig(), true);
        if (i < 1) {
            return null;
        }
        int i12;
        int i8 = 0;
        int i13 = 0;
        int i14 = 0;
        int i15 = 0;
        int i16 = 0;
        int i17 = 0;
        int i18 = 0;
        int i19 = 0;
        int i20 = 0;
        int i2;
        int i3;
        int width = bitmap2.getWidth();
        int height = bitmap2.getHeight();
        int[] iArr = new int[(width * height)];
        GuliLog.tracePrintError("pix", width + " " + height + " " + iArr.length);
        bitmap2.getPixels(iArr, 0, width, 0, 0, width, height);
        int i4 = width - 1;
        int i5 = height - 1;
        int i6 = width * height;
        int i7 = (i + i) + 1;
        int[] iArr2 = new int[i6];
        int[] iArr3 = new int[i6];
        int[] iArr4 = new int[i6];
        int[] iArr8;
        int[] iArr5 = new int[Math.max(width, height)];
        i6 = (i7 + 1) >> 1;
        i8 = i6 * i6;
        int[] iArr6 = new int[(i8 * PersonInfo.INCOMING_CALL_DISABLE_BIT)];
        for (i6 = 0; i6 < i8 * PersonInfo.INCOMING_CALL_DISABLE_BIT; i6++) {
            iArr6[i6] = i6 / i8;
        }
        int[][] iArr7 = (int[][]) Array.newInstance(Integer.TYPE, new int[]{i7, 3});
        int i9 = i + 1;
        int i10 = 0;
        int i11 = 0;
        for (i2 = 0; i2 < height; i2++) {

            for (i3 = -i; i3 <= i; i3++) {
                i12 = iArr[Math.min(i4, Math.max(i3, 0)) + i11];
                iArr8 = iArr7[i3 + i];
                iArr8[0] = (16711680 & i12) >> 16;
                iArr8[1] = (65280 & i12) >> 8;
                iArr8[2] = i12 & HeartRateInfo.HR_EMPTY_VALUE;
                i12 = i9 - Math.abs(i3);
                i19 += iArr8[0] * i12;
                i18 += iArr8[1] * i12;
                i17 += i12 * iArr8[2];
                if (i3 > 0) {
                    i13 += iArr8[0];
                    i20 += iArr8[1];
                    i8 += iArr8[2];
                } else {
                    i16 += iArr8[0];
                    i15 += iArr8[1];
                    i14 += iArr8[2];
                }
            }
            i12 = i19;
            i19 = i18;
            i18 = i17;
            i3 = i11;
            i11 = i;
            for (i17 = 0; i17 < width; i17++) {
                iArr2[i3] = iArr6[i12];
                iArr3[i3] = iArr6[i19];
                iArr4[i3] = iArr6[i18];
                i12 -= i16;
                i19 -= i15;
                i18 -= i14;
                iArr8 = iArr7[((i11 - i) + i7) % i7];
                i16 -= iArr8[0];
                i15 -= iArr8[1];
                i14 -= iArr8[2];
                if (i2 == 0) {
                    iArr5[i17] = Math.min((i17 + i) + 1, i4);
                }
                int i21 = iArr[iArr5[i17] + i10];
                iArr8[0] = (16711680 & i21) >> 16;
                iArr8[1] = (65280 & i21) >> 8;
                iArr8[2] = i21 & HeartRateInfo.HR_EMPTY_VALUE;
                i13 += iArr8[0];
                i20 += iArr8[1];
                i8 += iArr8[2];
                i12 += i13;
                i19 += i20;
                i18 += i8;
                i11 = (i11 + 1) % i7;
                iArr8 = iArr7[i11 % i7];
                i16 += iArr8[0];
                i15 += iArr8[1];
                i14 += iArr8[2];
                i13 -= iArr8[0];
                i20 -= iArr8[1];
                i8 -= iArr8[2];
                i3++;
            }
            i10 += width;
            i11 = i3;
        }
        for (i17 = 0; i17 < width; i17++) {
            i20 = 0;
            i8 = (-i) * width;
            i14 = 0;
            i15 = 0;
            i16 = 0;
            i11 = 0;
            i12 = -i;
            i3 = 0;
            i18 = 0;
            i19 = 0;
            i13 = 0;
            while (i12 <= i) {
                i2 = Math.max(0, i8) + i17;
                int[] iArr9 = iArr7[i12 + i];
                iArr9[0] = iArr2[i2];
                iArr9[1] = iArr3[i2];
                iArr9[2] = iArr4[i2];
                int abs = i9 - Math.abs(i12);
                i10 = (iArr2[i2] * abs) + i19;
                i19 = (iArr3[i2] * abs) + i18;
                i18 = (iArr4[i2] * abs) + i3;
                if (i12 > 0) {
                    i14 += iArr9[0];
                    i13 += iArr9[1];
                    i20 += iArr9[2];
                } else {
                    i11 += iArr9[0];
                    i16 += iArr9[1];
                    i15 += iArr9[2];
                }
                if (i12 < i5) {
                    i8 += width;
                }
                i12++;
                i3 = i18;
                i18 = i19;
                i19 = i10;
            }
            i12 = i18;
            i10 = i19;
            i19 = i3;
            i3 = i17;
            i8 = i20;
            i20 = i13;
            i13 = i14;
            i14 = i15;
            i15 = i16;
            i16 = i11;
            i11 = i;
            for (i18 = 0; i18 < height; i18++) {
                iArr[i3] = (((-16777216 & iArr[i3]) | (iArr6[i10] << 16)) | (iArr6[i12] << 8)) | iArr6[i19];
                i10 -= i16;
                i12 -= i15;
                i19 -= i14;
                int[] iArr10 = iArr7[((i11 - i) + i7) % i7];
                i16 -= iArr10[0];
                i15 -= iArr10[1];
                i14 -= iArr10[2];
                if (i17 == 0) {
                    iArr5[i18] = Math.min(i18 + i9, i5) * width;
                }
                i4 = iArr5[i18] + i17;
                iArr10[0] = iArr2[i4];
                iArr10[1] = iArr3[i4];
                iArr10[2] = iArr4[i4];
                i13 += iArr10[0];
                i20 += iArr10[1];
                i8 += iArr10[2];
                i10 += i13;
                i12 += i20;
                i19 += i8;
                i11 = (i11 + 1) % i7;
                iArr10 = iArr7[i11];
                i16 += iArr10[0];
                i15 += iArr10[1];
                i14 += iArr10[2];
                i13 -= iArr10[0];
                i20 -= iArr10[1];
                i8 -= iArr10[2];
                i3 += width;
            }
        }
        GuliLog.tracePrintError("pix", width + " " + height + " " + iArr.length);
        bitmap2.setPixels(iArr, 0, width, 0, 0, width, height);
        return bitmap2;
    }
}
